import 'package:architecture/os_size.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:study_demo/ui/getx_template/getx_template_generate_controller.dart';
import 'package:study_demo/widgets/text_button.dart';

import '../../widgets/yz_text.dart';

class GetXTemplateGeneratePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<GetXTemplateGenerateController>(
        init: GetXTemplateGenerateController(),
        builder: (controller) {
          return Scaffold(
            appBar: AppBar(
              title: Text('getx模板生成'),
            ),
            body: Container(
                height: windowHeight,
                margin: EdgeInsets.symmetric(horizontal: 15),
                child: Column(
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            MyTextField(
                              controller: controller.textEditingController,
                              width: 300,
                              hintText: '状态名',
                            ),
                            Row(
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                Checkbox(
                                    value: controller.isContainTitle.value,
                                    onChanged: (value) {
                                      controller.changeState();
                                    }),
                                Text('是否包含标题栏'),
                                Container(
                                    width: windowWidth * 0.1,
                                    margin: EdgeInsets.only(left: 15),
                                    child: TextField(
                                        controller: controller
                                            .titleTextEditingController,
                                        decoration: InputDecoration(
                                            hintText: '请输入标题内容'))),
                              ],
                            )
                          ],
                        ),
                        SizedBox(
                            height: 90,
                            child: _textButton('生成', controller, onPressed: () {
                              controller.generate();
                            })),
                        Expanded(
                            child: Container(
                          height: windowHeight * 0.8,
                          margin: EdgeInsets.only(top: 10),
                          padding: EdgeInsets.only(left: 15, top: 10),
                          child: TextField(
                            controller: controller.codeTextEditingController,
                            readOnly: true,
                            decoration: InputDecoration(
                              border: const OutlineInputBorder(),
                            ),
                            maxLines: 30,
                            style: TextStyle(color: Colors.green),
                          ),
                        ))
                      ],
                    ),
                    Container(
                        height: 50,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.end,
                          children: [
                            _textButton('复制模板', controller, onPressed: () {
                              controller.copyCode();
                            }),
                            _textButton('清空', controller, onPressed: () {
                              controller.clear();
                            }),
                          ],
                        ))
                  ],
                )),
          );
        });
  }

  _textButton(String text, GetXTemplateGenerateController controller,
      {Function? onPressed}) {
    return Container(
        margin: EdgeInsets.only(left: 15, right: 20),
        alignment: Alignment.center,
        child: MyTextButton(
            text: text,
            confirm: () {
              onPressed?.call();
            },
            backgroundColor: Colors.deepPurpleAccent,
            sideColor: Colors.deepPurpleAccent,
            textStyle: TextStyle(color: Colors.white)));
  }
}
